//
//  faceView.m
//  绘制脸
//
//  Created by Justsoso on 16/4/6.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "FaceView.h"

@implementation FaceView

- (void)setCenterY:(float)centerY
{
    _centerY = centerY;
    
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    
    CGPoint center = CGPointMake(rect.size.width/2, rect.size.height/2);
    CGFloat radius = rect.size.width / 2 - 5;
    
    /* 脸 */
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path addArcWithCenter:center radius:radius startAngle:0 endAngle:M_PI*2 clockwise:YES];
    path.lineWidth = 5;
    [[UIColor blueColor] setStroke];
    [path stroke];
    
    /* 左眼 */
    UIBezierPath *path2 = [UIBezierPath bezierPath];
    [path2 addArcWithCenter:CGPointMake(center.x-60, center.y-50) radius:15 startAngle:0 endAngle:M_PI*2 clockwise:YES];
    path2.lineWidth = 5;
    [[UIColor blueColor] setStroke];
    [path2 stroke];
    
    /* 右眼 */
    UIBezierPath *path3 = [UIBezierPath bezierPath];
    [path3 addArcWithCenter:CGPointMake(center.x+60, center.y-50) radius:15 startAngle:0 endAngle:M_PI*2 clockwise:YES];
    path3.lineWidth = 5;
    [[UIColor blueColor] setStroke];
    [path3 stroke];
    
    /* 嘴 */
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, center.x-70, center.y+60);
    CGContextAddQuadCurveToPoint(ctx, center.x, self.centerY, center.x+70, center.y+60);
    [[UIColor blueColor] setStroke];
    CGContextSetLineWidth(ctx, 5);
    CGContextStrokePath(ctx);

}


@end
